﻿/// <reference path="BaseChatWindow.js" />
//个人聊天窗口
IM.Control.PersonalChatWindow = function(conf) {
    IM.Control.BaseChatWindow.apply(this, arguments);

    this.Friend; //使用当前窗口与和对话的用户
    //最大化事件
    this.OnMaxSized = function() {
        this.ResetBaseContentSize();
        if (typeof this.Friend != "undefined") {
            this.SetTitle("您正在和 " + this.Friend.NickName + " 对话中");
        }


    };
    //窗口恢复事件
    this.OnNormalSized = function() {
        this.ResetBaseContentSize();
        if (typeof this.Friend != "undefined") {
            this.SetTitle("您正在和 " + this.Friend.NickName + " 对话中");
        }

    };
    //窗口最小化事件
    this.OnMinSized = function() {
        if (typeof this.Friend != "undefined") {
            this.SetTitle("好友:" + this.Friend.NickName);
        }

    };

    //显示个人聊天消息
    this.ShowMessage = function() {
        if (typeof this.Friend != "undefined" && typeof this.Friend.Messages != "undefined") {

            this.Friend.Messages.Each((function(obj) {
                return function(message) {
                    if (message.IsNew) {
                        var msg = "<span style='color:blue;'>" + obj.Friend.NickName + " " + IM.GetTimeFromServerTimeString(message.SendTime) + "</span><br/>" + message.Content + "<p>"
                        obj.AddMessageToShowArea(msg);
                        message.IsNew = false;
                    }
                };
            })(this));
        }
    };

    //发送消息
    this.SendMessage = function() {
        var inputContent = this.GetInputContent(); //获取输入信息
        if (inputContent.toLowerCase().indexOf("<p>") == 0) {//ie的iframe会自动在开始添加段落标记,删除掉开始的段落标记
            inputContent = inputContent.substring(3, inputContent.length);
        }
        if (inputContent.replace(" ", "").replace("&nbsp;", "").replace("<br>", "").replace("<BR>", "").replace("<p>", "").replace("<P>", "").replace("</P>", "").length == 0) {
            alert("消息不能为空!");
            return;
        }
        this.ClearInputArea(); //清空输入框
        var msg = "<span style='color:blue;'>" + IM.Chat.CurrentUserManager.User.NickName + " " + IM.GetCurrentTimeString() + "</span><br/>" + inputContent + "<p>"
        this.AddMessageToShowArea(msg);
        this.ShowAreaScrollToBottom();

        //发出消息
        IM.Chat.MessageManager.SendMessage(
        IM.Chat.CurrentUserManager.User.UserId,
        this.Friend.UserId,
        inputContent,
        IM.InstantMessageType.PersonalMessage);
    };

    this.PersonalChatWindowInit = function() {
        if (typeof this.Friend != "undefined") {
            this.SetTitle("您正在和 " + this.Friend.NickName + " 对话中");
        }
    };

    this.PersonalChatWindowInit();
};